#include "ServerControl.hpp"
#include <fmt/format.h>
#include <stdexcept>

ServerControl::ServerControl(std::string ip,std::string port)
  : client(fmt::format("http://{}:{}",ip,port))
{

}

ServerControl::ServerControl(std::string URL)
  : client(URL)
{}

ServerControl::~ServerControl()
{

}

void ServerControl::StartMonitor()
{
  auto res=client.Get("/Camera/StartMonitor");
  if(res==nullptr || res->status!=200)
    throw std::runtime_error("启动实时显示功能失败");
}

void ServerControl::StopMonitor()
{
  auto res=client.Get("/Camera/StopMonitor");
  if(res==nullptr || res->status!=200)
    throw std::runtime_error("停止实时显示功能失败");
}

void ServerControl::StartRecord(std::string projectName,std::string taskName)
{
  auto res=client.Get(fmt::format("/Camera/StartRecord?ProjectName={}&TaskName={}",projectName,taskName));
  if(res==nullptr || res->status!=200)
    throw std::runtime_error("启动录制功能失败");
}

void ServerControl::StopRecord()
{
  auto res=client.Get("/Camera/StopRecord");
  if(res==nullptr || res->status!=200)
    throw std::runtime_error("停止录制失败");
}
